package 生产者消费者;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;

public class Test {
    public static void main(String[] args) {
        BlockingQueue<Integer>blockingQueue=new ArrayBlockingQueue<Integer>(10);
        Thread producer =new Thread(()->{
            for (int i = 0; i < 20; i++) {
                System.out.println("生产者"+i);
                try {
                    blockingQueue.put(i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        Thread consumer =new Thread(()->{
            for (int i = 0; i < 20; i++) {
                System.out.println("消费者"+i);
                try {
                    blockingQueue.take();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        producer.start();
        consumer.start();

    }
}
